c# choose first n elements from list

68

c# choose first n elements from list -

var secondFiveItems = myList.Skip(5).Take(5);

c# select first value from list -

lstComp.First();
//You can also use FirstOrDefault() just in case lstComp does not contain any items.

//To get the Component Value:
var firstElement = lstComp.First().ComponentValue("Dep");

//This would assume there is an element in lstComp. An alternative and safer way would be...
var firstOrDefault = lstComp.FirstOrDefault();
if (firstOrDefault != null) 
{
    var firstComponentValue = firstOrDefault.ComponentValue("Dep");
}

c# choose first n elements from list -

var firstFiveItems = myList.Take(5);

Comments

Submit
0 Comments